<?php
	
	require '../../config.php';	
	$_codigo = $_REQUEST['id'];
	
		$registros=mysql_query("select * from  clientesventas where idclientesventas='".$_codigo."' limit 1") or die("Problemas en el select:".mysql_error());
		if (mysql_num_rows($registros) == 0)
		{
			echo "0";
		}
		else
		{	
			$data = array();
			$row = mysql_fetch_array($registros);
				
			    $data[] = $row['idclientesventas'];
    			$data[] = _convert($row['nombre']);    			
    			$data[] = $row['fechacreacion'];    			
    			$data[] = _convert($row['direccion']);    			
    			$data[] = $row['telefono'];    		
    			$data[] = _convert($row['contacto']);    			
    			$data[] = $row['telcontacto'];
    			$data[] = _convert($row['cargo']);		 
    			$data[] = _convert($row['email']);
    			$data[] = $row['org']; 
    			$data[] = $row['tipo'];
    			$data[] = $row['ruc'];    			
    			$data[] = $row['dv']; 
			
			echo json_encode($data);
		}
			
	
	function _convert($content) {
		if(!mb_check_encoding($content, 'UTF-8')
		OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
	
			$content = mb_convert_encoding($content, 'UTF-8');
	
			if (mb_check_encoding($content, 'UTF-8')) {
				// log('Converted to UTF-8');
			} else {
				// log('Could not converted to UTF-8');
			}
		}
		return $content;
	}
?>
